package org.tio.im.server.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.im.common.cache.caffeineredis.CaffeineRedisCacheManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public final class RedisUtil {

    private static Logger logger = LoggerFactory.getLogger(RedisUtil.class);


    /**
     * 获取redis键值-object
     * 
     * @param key
     * @return
     */
    public static JSONObject getJsonInfo(String token) {
        try {
        	 String bytes = CaffeineRedisCacheManager.getCache("default").get(token, String.class);
        	 logger.info("getJsonInfo发安徽信息token:"+token+",data:"+bytes);
        	if(bytes != null && bytes.startsWith("\"")) {
        		bytes = bytes.substring(1, bytes.length()-1);
        		bytes = bytes.replaceAll("\\\\", "");
			}
       	 logger.info("处理完getJsonInfo发安徽信息token:"+token+",data:"+bytes);
        	if(bytes != null) {
        		return JSON.parseObject(bytes);
        	}
            return null;
        } catch (Exception e) {
            logger.error("getJsonObject获取redis键值异常:key=" + token + " cause:", e);
        } 
        return null;
    }
}